package com.kaibes.object.code;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import com.kaibes.object.annotation.BesResource;

public interface BesClassParser {

	public static List<Class<?>> getMXClass(String packgeName) {
		List<String> clazzList = BesClassScanning.getClassNameWithChild(packgeName);
		List<Class<?>> classList = new ArrayList<>();
		for (String clazzName : clazzList) {
			try {
				Class<?> clazzC = Class.forName(clazzName);
				if (clazzC.isAnnotationPresent(BesResource.class)) {
					classList.add(clazzC);
				}
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		return classList;
	}

	public static List<Method> getMXMethod(Class<?> clazz) {
		Method[] methods = clazz.getDeclaredMethods();

		List<Method> methodList = new ArrayList<>();
		for (Method method : methods) {
			if (method.isAnnotationPresent(BesResource.class)) {
				methodList.add(method);
			}
		}
		return methodList;
	}

	public static List<Field> getMXField(Class<?> clazz) {
		Field[] fields = clazz.getDeclaredFields();
		List<Field> fieldList = new ArrayList<>();
		for (Field field : fields) {
			if (field.isAnnotationPresent(BesResource.class)) {
				fieldList.add(field);
			}
		}
		return fieldList;
	}
}
